<?php

namespace app\api\controller\logistics;

use app\common\controller\qyg\Api;
use app\common\model\Third;
use think\Exception;
use think\Request;

class User extends Api
{
    public $noNeedRight = "*";

    public $noNeedLogin = ["auth_login"];

    public $service;

    public function __construct()
    {
        parent::__construct();
        $this->service= new \app\common\service\logistics\User();
    }

    /**
     * 微信授权
     * @return void
     */
    public function auth_login(Request $request)
    {
        if(!$this->request->isPost()){
            $this->error("非法请求");
        }
        try {
            $data = $this->service->auth_login($request);
            $this->success("OK",$data);
        }catch (Exception $e){
            $this->error($e->getMessage());
        }
    }

    /**
     * 修改资料
     * @return void
     */
    public function user_edit(Request $request)
    {
        if(!$this->request->isPost()){
            $this->error("非法请求");
        }
        try {
            $data = $this->service->user_edit($this->auth->id,$request);
            $this->success("OK",$data);
        }catch (Exception $e){
            $this->error($e->getMessage());
        }
    }

    /**
     * 修改资料
     * @return void
     */
    public function auth_mobile(Request $request)
    {
        if(!$this->request->isPost()){
            $this->error("非法请求");
        }
        try {
            $data = $this->service->auth_mobile($this->auth->id,$request);
            $this->success("OK",$data);
        }catch (Exception $e){
            $this->error($e->getMessage());
        }
    }

    /**
     * 用户基本信息
     * @return void
     */
    public function user_info()
    {
        try {
            $data = $this->service->user_info($this->auth->id);
            $this->success("OK",$data);
        }catch (Exception $e){
            $this->error($e->getMessage());
        }
    }

    /**
     * 实名信息
     * @return void
     */
    public function real_info()
    {
        try {
            $data = $this->service->real_info($this->auth->id);
            $this->success("OK",$data);
        }catch (Exception $e){
            $this->error($e->getMessage());
        }
    }

    /**
     * 添加实名
     * @return void
     */
    public function auth_user(Request $request)
    {
        if(!$this->request->isPost()){
            $this->error("非法请求");
        }
        try {
            $data = $this->service->auth_user($this->auth,$request);
            $this->success("认证成功",$data);
        }catch (Exception $e){
            $this->error($e->getMessage());
        }
    }
}